<div class="page-header" style="padding-bottom: 0px;">
    <h3>Service Request</h3>
</div>


<div class="row-fluid">
    <div class="span12">
        <h4>Filter</h4>
        <?php echo $this->Form->create('Query', array('id' => 'form-query', 'class' => 'form form-horizontal', 'inputDefaults' => array('label' => false,'div' => false)));?>
        <table class="table ">
            <tr><td>Start Date</td><td>End Date</td><td>Session</td><td>Index Number</td><td>Fee Type</td></tr>
            <tr>
                <td>
                    <?php echo $this->Form->input('start_dt', array('id'=>'start_dt','placeholder' => 'yyyy-mm-dd', 'default'=>$default_start_dt,'class' => 'input-medium','div' => false, 'label' => false));?>
                </td>
                <td>
                    <?php echo $this->Form->input('end_dt', array('id'=>'end_dt','placeholder' => 'yyyy-mm-dd', 'default'=>$default_end_dt,'class' => 'input-medium','div' => false, 'label' => false));?>
                </td>
                <td>
                    <?php echo $this->Form->input('academic_session', array('id'=>'academic_session', 'options'=>$academic_sessions, 'default'=>$aca_ses, 'class' => 'input-medium','div' => false, 'label' => false));?>
                </td>
                <td>
                    <?php echo $this->Form->input('index_no', array('id'=>'index_no','class' => 'input-medium','default'=>$index_no,'div' => false, 'label' => false));?>
                <td>
                    <?php echo $this->Form->input('fee_type', array('id'=>'fee_type', 'options'=>$fee_types,'default'=>$default_fee_type,'class' => 'input-medium','div' => false, 'label' => false,));?>
                </td>
            </tr>
            <tr>
                <td colspan="4">
                    <div class="controls">
                        <button type="submit" id="re_query-btn" class="btn btn-primary">Query</button>
                       <!-- <button type="button"  id="print-btn" class="btn">Print</button>
                        <button type="button"  id="export-btn" class="btn">Export</button>-->
                    </div>
                </td>
            </tr>
        </table>
        <?php echo $this->Form->end();?>

        <table id="flex">
            <!-- <thead>
                 <tr><th>Student Name</th><th>Index Number</th><th>Fee Type</th><th>Fee Amount</th><th>Paid</th><th>Balance</th></tr>
             </thead>-->
            <tbody>
            <?php
            $tl_paid = 0;
            $tl_fee_amount = 0;
            $tl_bal = 0;
            foreach ($data_table as $obj) {
                $paid = doubleval($obj['paid']) ;
                $fee_amount = doubleval($obj['fee_amount']);
                $bal = doubleval($obj['balance']);

                $tl_paid = $tl_paid + $paid;
                $tl_fee_amount = $tl_fee_amount + $fee_amount;
                $tl_bal = $tl_bal + $bal;

                $id  = $obj['id'];
                $btn = $obj['served'];
                if( $obj['served'] == 'No'){
                    $btn= " <button type='button' data-id='$id' class='btn btn-primary btn-small served-btns'>Served</button>";
                }

                ?>
                <tr>
                    <td><?php echo $obj['index_number'];?></td>
                    <td><?php echo $obj['name'];?></td>
                    <td><?php echo $obj['fee'];?></td>
                    <td><?php echo $obj['fee_amount'];?></td>
                    <td><?php echo $obj['paid'];?></td>
                    <td><?php echo $controller->formatNumber($obj['balance'],'money');?></td>
                    <td><?php echo $btn;?></td>
                    <td><?php echo $this->App->covertDate($obj['request_date'],'ui');?></td>
                    <td><?php echo !empty($obj['served_date'])?$this->App->covertDate($obj['served_date'],'ui'):'';?></td>

                </tr>
                <?php
                //}
            }
            if($tl_fee_amount > 0){
                ?>
                <tr>
                    <td></td>
                    <td></td>
                    <td><strong>Totals</strong></td>
                    <td><strong><?php echo $controller->formatNumber($tl_fee_amount,'money'); ?></strong></td>
                    <td><strong><?php echo $controller->formatNumber($tl_paid,'money');?></strong></td>
                    <td><strong><?php echo $controller->formatNumber($tl_bal,'money');?></strong></td>
                    <td></td>
                    <td></td>
                    <td></td>

                </tr>
            <?php
            }
            ?>
            </tbody>
        </table>



        <form id="print-export-form" method="post" action="<?php echo $this->Html->url(array('controller' => 'Staff', 'action' => 'print_export_report')); ?>" target="PrintExportWindow">
            <input type="hidden" name="data_type" id="data_type" value="" />
            <input type="hidden" name="data_start_dt" id="data_start_dt"  value="" />
            <input type="hidden" name="data_end_dt" id="data_end_dt"  value="" />
            <input type="hidden" name="data_program_id" id="data_program_id"  value="" />
            <input type="hidden" name="data_section" id="data_section"  value="" />
        </form>
    </div>
</div>

<input type="hidden" id="update-service-requests-url" value="<?php echo $this->Html->url(array('controller' => 'Staff', 'action' => 'update_service_request')); ?>" />

<?php
    echo $this->Html->script('staff/service_requests.js');
?>